/******************************************************************************
* File description: password.qml
* Function: 密码窗口
* Current Version: 1.0.0
* Author: 张宇轩
* Date: 2024-08-19
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14
import SvgImage 1.0

Item {
    id: root

    /* property 定义开始 */
    // 密码
    property string passwordText: ""

    // 信号
    signal submit(string pwd) // 确认
    signal cancel() // 取消

    // c++信号的槽函数
    Connections {
        target: passwordUi

        // 清空密码框
        function onClearPassword(){
            pwdInput.clearTextInput()
            root.passwordText = ""
        }
    }

    /* property 定义结束 */

    Rectangle {
        id: passwordCon
        anchors.fill: parent
        color: "#FFF"
        radius: 12

        ColumnLayout {
            id: passwordConColLayout
            anchors {
                fill: parent
                leftMargin: 56
                rightMargin: 56
                topMargin: 5
            }
            spacing: 16

            CustomVerSpacerItem {}

            // 锁图标
            Item {
                id: lockCon
                Layout.preferredWidth: 40
                Layout.preferredHeight: 40
                Layout.alignment: Qt.AlignHCenter

                SvgImage {
                    id: losgSvg
                    anchors.fill: parent
                    source: "qrc:/icons/lock.svg"
                }
            }

            // 请输入密码文字
            Label {
                id: pleaseInputPwd
                Layout.alignment: Qt.AlignHCenter
                font {
                    pixelSize: 16
                }
                color: "#FF222222"
                text: "请输入密码"
            }

            // 密码输入框
            BaseTextInput {
                id: pwdInput
                Layout.fillWidth: true
                Layout.preferredHeight: 48
                Layout.alignment: Qt.AlignHCenter
                inputHAlign: TextInput.AlignHCenter
                inputBgColor: "#FFF5F5F5"
                inputRadius: 12
                inputBorderWidth: 0
                placeholderText: ""
                inputEchoMode: TextInput.Password

                onTextEdited: {
                    root.passwordText = text
                }
            }

            // 按钮
            Item {
                id: buttonCon
                Layout.fillWidth: true
                Layout.preferredHeight: 40
                Layout.topMargin: 24
                Layout.bottomMargin: 40

                RowLayout {
                    id: btnRowLayout
                    anchors.fill: parent
                    spacing: 8

                    CustomHorSpacerItem {}

                    // 取消
                    PureImgButton {
                        Layout.preferredWidth: 120
                        Layout.preferredHeight: 40
                        pureBtnWidth: 120
                        pureBtnHeight: 40
                        pureText: "取消"
                        pureIconWidth: 0

                        onReleased: {
                            root.cancel()
                        }
                    }

                    // 确认
                    PureImgButton {
                        Layout.preferredWidth: 120
                        Layout.preferredHeight: 40
                        pureBtnWidth: 120
                        pureBtnHeight: 40
                        pureText: "确定"
                        pureBtnBorderWidth: 0
                        pureBtnColor: "#FF2F42CD"
                        pureFontColor: "#FFFFFFFF"
                        pureIconWidth: 0

                        onReleased: {
                            root.submit(root.passwordText)
                        }
                    }

                    CustomHorSpacerItem {}
                }
            }

            CustomVerSpacerItem {}
        }
    }
}
